package com.bdqn.t350.service;

import com.bdqn.t350.dao.SysUserMapper;
import com.bdqn.t350.pojo.Page;
import com.bdqn.t350.pojo.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("sysUserServiceImp")
public class SysUserServiceImp implements SysUserService {

    @Resource
    //@Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public List<SysUser> getListBiz() {
        return sysUserMapper.getList();
    }

    @Override
    public int addService(SysUser sysUser) {
        return sysUserMapper.add(sysUser);
    }

    @Transactional
    @Override
    public boolean addService(List<SysUser> list) {
        boolean result = true;
        for (SysUser sysUser : list) {
            if (sysUserMapper.add(sysUser) < 1) {
                result = false;
            }
            //System.out.println(1/0);
        }
        return result;
    }

    @Override
    public SysUser loginBiz(SysUser sysUser) {
        return sysUserMapper.login(sysUser);
    }

    @Override
    public List<SysUser> getListPageBiz(Page page, SysUser sysUser) {
        return sysUserMapper.getListPage((page.getCurrentPage() - 1) * page.getPageSize(),
                page.getPageSize(), sysUser);
    }

    @Override
    public int getCountPageBiz(SysUser sysUser) {
        return sysUserMapper.getCountPage(sysUser);
    }
}
